﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Configuration;
using System.Configuration;
using System.Web.Configuration;
using System.Web;

namespace GoShopping.BLL
{
    /// <summary>
    /// 站点设置相关
    /// </summary>
    public class SiteSetting
    {
        /// <summary>
        /// Configuration
        /// </summary>
        private static readonly Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);

        #region Email Section
        /// <summary>
        /// 获取邮件配置节
        /// </summary>
        /// <returns></returns>
        public SmtpSection GetSmtpSection()
        {
            SmtpSection smtp = (SmtpSection)config.GetSection("system.net/mailSettings/smtp");
            return smtp;
        }

        /// <summary>
        /// 保存邮件配置节
        /// go_shopping2009@163.com
        /// </summary>
        /// <param name="host">smtp.163com</param>
        /// <param name="userName">GoShopping</param>
        /// <param name="password">goshopping</param>
        /// <param name="From">go_shopping2009</param>
        public void SaveSmtpSection(string host, string userName, string password, string From)
        {
            SmtpSection smtp = GetSmtpSection();
            smtp.Network.Host = host;
            smtp.Network.UserName = userName;
            smtp.Network.Password = password;
            smtp.From = From;
            config.Save(ConfigurationSaveMode.Modified);
        }
        #endregion
       
    }
}
